Get all combinations of letters from a different keys¶
itertools.product(*[DOL[k] for k in DOL(keys())]
Create and display all combinations of letters, selecting each letter
from a different key in a dictionary.
Sample data:
{‘1’: [‘a’, ‘b’], ‘2’: [‘c’, ‘d’]}
Expected output:
ac
ad
bc
bd
import itertools
DOL = {
'1': ['a', 'b'],
'2': ['c', 'd']
}
for combo in itertools.product(*[DOL[k] for k in sorted(DOL.keys())]):
print(''.join(combo))
Output:
ac
ad
bc
bd